/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.manage.news;
import shop.core.common.bean.JSONResult;
import shop.core.util.KeyValueHelper;
import shop.core.Services;
import shop.core.util.MD5;
import shop.core.util.WriteToHtmlUtils;
import shop.services.manage.news.NewsService;
import shop.services.manage.news.bean.News;
import shop.core.BaseController;
import shop.core.RequestHolder;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import shop.services.manage.product.bean.Product;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**   
 * @类名称：NewsAction      
 * @创建人：wzl
 * @创建时间：2018-05-09 下午19:22:34      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/manage/news/")
public class NewsAction extends BaseController<News> {
    private static final Logger logger = LoggerFactory.getLogger(NewsAction.class);
    @Autowired
    private NewsService newsService;
    private static final String page_toList = "/manage/news/newsList";
    private static final String page_toAdd = "/manage/news/newsAdd";
    private static final String page_toEdit = "/manage/news/newsEdit";
    public NewsService getService() {
        return newsService;
    }

    private NewsAction(){
        super.page_toList = page_toList;
        super.page_toAdd = page_toAdd;
        super.page_toEdit = page_toEdit;
    }

    @RequestMapping(value = "createHtmlJson", method = RequestMethod.POST)
    @ResponseBody
    public JSONResult createHtmlJson(HttpServletRequest request) throws Exception {
        jsonResult = new JSONResult();
        List<News> allList= getService().selectList(new News());
        if(allList.size()==0){
            return  jsonResult;
        }
        for (int i = 0 ; i < allList.size() ; i++) {
            Map data = new HashMap();
            data.put("o",allList.get(i));
            WriteToHtmlUtils.CreateHtmlFile(request,"zxxq.ftl",data,"/zlkx/"+allList.get(i).getId());
        }
        return jsonResult;
    }
}
